package com.fh.fruit.controller.activity;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.fh.controller.base.BaseController;
import com.fruit.service.promotion.ActivityManager;

@Controller
@RequestMapping(value = "/activityMultil")
public class ActivityMultilController extends BaseController {
	String menuUrl = "activityMultil/listActivityTree.do"; // 地址(权限用)

	@Autowired
	private ActivityManager activityService;

	@RequestMapping(value = "/tree")
	public ModelAndView tree(String code, Integer userId, Integer top) {
		ModelAndView mv = this.getModelAndView();
		try {
			mv.addObject("code", code);
			mv.addObject("userId", userId);
			mv.addObject("top", top);
			mv.setViewName("farm/activity/activity_mutil_tree");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return mv;
	}

	@RequestMapping(value = "/listActivityTree", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public Map<String, Object> listActivityTree(String code, Integer userId, Integer top) throws Exception {
		Map<String, Object> resMap = new HashMap<>();
		try {
			resMap = activityService.getActivityTreeList(code, userId, top);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return resMap;
	}

	@RequestMapping(value = "/addActivityTree", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public Map<String, Object> addActivityTree(String code, Integer userId, String phone) throws Exception {
		Map<String, Object> resMap = new HashMap<>();
		try {
			resMap = activityService.addActivityTree(code, userId, phone);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return resMap;
	}

	@RequestMapping(value = "/updateActivityTree", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public Map<String, Object> updateActivityTree(String code, Integer userId, String phone) throws Exception {
		Map<String, Object> resMap = new HashMap<>();
		try {
			resMap = activityService.updateActivityTree(code, userId, phone);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return resMap;
	}
}
